package com.douqu.game.core.entity.world;

import com.bean.core.buffer.ByteBuffer;
import com.douqu.game.core.entity.EntityObject;
import com.douqu.game.core.factory.ConstantFactory;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: miracle.
 * Description:
 * Date: 2018/3/20 0020 下午 6:30
 * Huan Yu Copyright (c) 2017 All Rights Reserved.
 */
public class WorldAuctionBean extends EntityObject{

    /**
     * 读取excel表的ID
     */
    private int auctionConfigId;

    /**
     * 这条拍卖商品的ID
     */
    private int id;

    /**
     * 当前价格
     */
    private int currentPrice;

    /**
     * 当前出价玩家
     */
    private String currentPlayer;

    /**
     * 开始时间
     */
    private long startTime;

    /**
     * 状态  0 拍卖中  1 结束
     */
    private int state;

    /**
     * 参与分红用户列表
     */
    private List<String> playerList;

    /**
     * 参与此次拍卖的玩家
     */
    private List<String> auctionList;

    /**
     * 结束时间
     */
    private long endTime;
    /**
     * 来源
     */
    private int source;

    public void writeTo(ByteBuffer buffer){
        buffer.writeInt(auctionConfigId);
        buffer.writeInt(id);
        buffer.writeInt(currentPrice);
        buffer.writeUTF(currentPlayer);
        buffer.writeLong(startTime);
        buffer.writeInt(state);
        buffer.writeInt(playerList.size());
        for(int j = 0; j < playerList.size(); j++){
            buffer.writeUTF(playerList.get(j));
        }
        buffer.writeInt(auctionList.size());
        for(int j = 0; j < auctionList.size(); j++){
            buffer.writeUTF(auctionList.get(j));
        }
        buffer.writeLong(endTime);
        buffer.writeByte(source);
    }

    public void loadFrom(ByteBuffer buffer){
        auctionConfigId = buffer.readInt();
        id = buffer.readInt();
        currentPrice = buffer.readInt();
        currentPlayer = buffer.readUTF();
        startTime = buffer.readLong();
        state = buffer.readInt();
        int length = buffer.readInt();
        List<String> players = new ArrayList<>();
        for(int j = 0;j<length;j++){
            players.add(buffer.readUTF());
        }
        playerList = players;

        List<String> auctionPlayers = new ArrayList<>();
        length = buffer.readInt();
        for (int j = 0;j<length;j++){
            auctionPlayers.add(buffer.readUTF());
        }
        auctionList = auctionPlayers;
        endTime =  buffer.readLong();
        source = buffer.readByte();
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getCurrentPrice() {
        return currentPrice;
    }

    public void setCurrentPrice(int currentPrice) {
        this.currentPrice = currentPrice;
    }

    public String getCurrentPlayer() {
        return currentPlayer;
    }

    public void setCurrentPlayer(String currentPlayer) {
        this.currentPlayer = currentPlayer;
    }

    public long getStartTime() {
        return startTime;
    }

    public void setStartTime(long startTime) {
        this.startTime = startTime;
    }

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }

    public List<String> getPlayerList() {
        return playerList;
    }

    public void setPlayerList(List<String> playerList) {
        this.playerList = playerList;
    }

    public List<String> getAuctionList() {
        return auctionList;
    }

    public void setAuctionList(List<String> auctionList) {
        this.auctionList = auctionList;
    }

    public int getAuctionConfigId() {
        return auctionConfigId;
    }

    public void setAuctionConfigId(int auctionConfigId) {
        this.auctionConfigId = auctionConfigId;
    }

    public long getEndTime() {
        return endTime;
    }

    public void setEndTime(long endTime) {
        this.endTime = endTime;
    }

    public int getSource() {
        return source;
    }

    public void setSource(int source) {
        this.source = source;
    }

    @Override
    public String toString() {
        return "WorldAuctionBean{" +
                "auctionConfigId=" + auctionConfigId +
                ", id=" + id +
                ", currentPrice=" + currentPrice +
                ", currentPlayer='" + currentPlayer + '\'' +
                ", startTime=" + startTime +
                ", state=" + state +
                ", playerList=" + playerList +
                ", auctionList=" + auctionList +
                ", endTime=" + endTime +
                ", source=" + source +
                '}';
    }
}
